﻿using Microsoft.EntityFrameworkCore;
using TodoApp.TMS_Basics;
using TodoApp.TMS_Basics.TMS_cargoowner;
using TodoApp.TMS_Basics.TMS_coordination;
using TodoApp.TMS_Basics.TMS_line;
using TodoApp.TMS_Basics.TMS_Oilcost;
using TodoApp.TMS_Contract;
using TodoApp.TMS_maintain;
using TodoApp.TMS_maintain.TMS_accident;
using TodoApp.TMS_maintain.TMS_Maintenancerecord;
using TodoApp.TMS_maintain.TMS_repair;
using TodoApp.TMS_maintain.TMS_tyre;
using TodoApp.TMS_maintain.TNS_Violation;
using TodoApp.TMS_material.MaterialsConsumings;
using TodoApp.TMS_material.MaterialsProcurements;
using TodoApp.TMS_material.ProductionPlace;
using TodoApp.TMS_personnelmatters.Departments;
using TodoApp.TMS_personnelmatters.Employeess;
using TodoApp.TMS_personnelmatters.Inductions;
using TodoApp.TMS_personnelmatters.Positions;
using TodoApp.TMS_settlement.Charges;
using TodoApp.TMS_settlement.Inputs;
using TodoApp.TMS_settlement.Outputs;
using TodoApp.TMS_settlement.Payments;
using TodoApp.TMS_settlement.Pays;
using TodoApp.TMS_SetUp;
using TodoApp.TMS_SetUp.Departments;
using TodoApp.TMS_SetUp.Menus;
using TodoApp.TMS_SetUp.Operators;
using TodoApp.TMS_SetUp.Positions;
using TodoApp.TMS_SetUp.RoleMenus;
using TodoApp.TMS_SetUp.Roles;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using TMS_cargoownerModel = TodoApp.TMS_Basics.TMS_cargoownerModel;

namespace TodoApp.EntityFrameworkCore
{
    [ReplaceDbContext(typeof(IIdentityDbContext))]
    [ReplaceDbContext(typeof(ITenantManagementDbContext))]
    [ConnectionStringName("Default")]
    public class TodoAppDbContext :
        AbpDbContext<TodoAppDbContext>,
        IIdentityDbContext,
        ITenantManagementDbContext
    {
        /* Add DbSet properties for your Aggregate Roots / Entities here. */

        #region Entities from the modules

        /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext
         * and replaced them for this DbContext. This allows you to perform JOIN
         * queries for the entities of these modules over the repositories easily. You
         * typically don't need that for other modules. But, if you need, you can
         * implement the DbContext interface of the needed module and use ReplaceDbContext
         * attribute just like IIdentityDbContext and ITenantManagementDbContext.
         *
         * More info: Replacing a DbContext of a module ensures that the related module
         * uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
         */

        //Identity
        public DbSet<IdentityUser> Users { get; set; }
        public DbSet<IdentityRole> Roles { get; set; }
        public DbSet<IdentityClaimType> ClaimTypes { get; set; }
        public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
        public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
        public DbSet<IdentityLinkUser> LinkUsers { get; set; }

        // Tenant Management
        public DbSet<Tenant> Tenants { get; set; }
        public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }

        #endregion

        #region 基础管理-黄启轩

        /// <summary>
        /// 车辆管理
        /// </summary>
        public DbSet<TMS_VehicleModel> TMS_VehicleModel { get; set; }

        /// <summary>
        /// 货主管理
        /// </summary>

        public DbSet<TMS_cargoownerModel> TMS_cargoownerModel { get; set; }

        /// <summary>
        /// 线路管理
        /// </summary>
        public DbSet<TMS_lines> TMS_lines { get; set; }

        /// <summary>
        /// 外协单位管理
        /// </summary>
        public DbSet<TMS_coordinationModel> TMS_coordinationModel { get; set; }

        /// <summary>
        /// 油费管理
        /// </summary>
        public DbSet<TMS_OilcostModel> TMS_OilcostModel { get; set; }
        #endregion

        #region 人事-张笑宇

        /// <summary>
        /// 离职表
        /// </summary>
        public DbSet<TMS_Departure> TMS_Departure { get; set; }

        /// <summary>
        /// 员工表
        /// </summary>
        public DbSet<TMS_Employees> TMS_Employees { get; set; }

        /// <summary>
        /// 入职表
        /// </summary>
        public DbSet<TMS_Induction> TMS_Induction { get; set; }
        /// <summary>
        /// 转正表
        /// </summary>
        public DbSet<TMS_Positive> TMS_Positive { get; set; }

        #endregion

        #region 设置-张笑宇

        /// <summary>
        /// 操作员
        /// </summary>
        public DbSet<TMS_Operator> TMS_Operator { get; set; }

        /// <summary>
        /// 部门管理
        /// </summary>
        public DbSet<TMS_Department> TMS_Department { get; set; }

        /// <summary>
        /// 菜单表
        /// </summary>
        public DbSet<TMS_Menu> TMS_Menu { get; set; }

        /// <summary>
        /// 职位表
        /// </summary>
        public DbSet<TMS_Position> TMS_Position { get; set; }

        /// <summary>
        /// 菜单角色表
        /// </summary>
        public DbSet<TMS_RoleMenu> TMS_RoleMenu { get; set; }

        /// <summary>
        /// 角色表
        /// </summary>
        public DbSet<TMS_Role> TMS_Role { get; set; }
        #endregion

        #region 结算-张笑宇

        /// <summary>
        /// 应收费管理
        /// </summary>
        public DbSet<TMS_Charge> TMS_Charge { get; set; }

        /// <summary>
        /// 进项发票
        /// </summary>
        public DbSet<TMS_Input> TMS_Input { get; set; }

        /// <summary>
        /// 应付费管理
        /// </summary>
        public DbSet<TMS_Pay> TMS_Pay { get; set; }

        /// <summary>
        /// 销项发票
        /// </summary>
        public DbSet<TMS_Output> TMS_Output { get; set; }

        /// <summary>
        /// 付款管理
        /// </summary>
        public DbSet<TMS_Payment> TMS_Payment { get; set; }

        #endregion

        #region 合同-郭辉

        /// <summary>
        /// 合同表
        /// </summary>
        public DbSet<TMS_Contracts> TMS_Contracts { get; set; }

        /// <summary>
        /// 流程实例表
        /// </summary>
        public DbSet<TMS_FlowInstance> TMS_FlowInstance { get; set; }

        /// <summary>
        /// 记录表
        /// </summary>
        public DbSet<TMS_FlowRecord> TMS_FlowRecord { get; set; }

        /// <summary>
        /// 节点表
        /// </summary>
        public DbSet<TMS_Node> TMS_Node { get; set; }
        #endregion

        #region 物资-郭辉

        /// <summary>
        /// 物资领用
        /// </summary>
        public DbSet<TMS_MaterialsConsuming> TMS_MaterialsConsuming { get; set; }

        /// <summary>
        /// 物资采购表
        /// </summary>
        public DbSet<TMS_MaterialsProcurement> TMS_MaterialsProcurement { get; set; }

        /// <summary>
        /// 入库管理
        /// </summary>
        public DbSet<TMS_StorageManagement> TMS_StorageManagement { get; set; }
        /// <summary>
        /// 产地
        /// </summary>
        public DbSet<TMS_ProductionPlace> TMS_ProductionPlace { get; set; }
        #endregion

        #region 维护-黄启轩

        /// <summary>
        /// 维修管理
        /// </summary>
        public DbSet<TMS_repairModel> TMS_repairModel { get; set; }

        public DbSet<TMS_MaintenancerecordModel> TMS_MaintenancerecordModel { get; set; }

        public DbSet<TMS_ViolationModel> TMS_ViolationModel { get; set; }

        public DbSet<TMS_accidentModel> TMS_accidentModel { get; set; }

        public DbSet<TMS_tyreModel> TMS_tyreModel { get; set; }

        #endregion

        public DbSet<TMS_Dictionary> TMS_DictionaryTable { get; set; }

        public TodoAppDbContext(DbContextOptions<TodoAppDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Include modules to your migration db context */

            builder.ConfigurePermissionManagement();
            builder.ConfigureSettingManagement();
            builder.ConfigureBackgroundJobs();
            builder.ConfigureAuditLogging();
            builder.ConfigureIdentity();
            builder.ConfigureIdentityServer();
            builder.ConfigureFeatureManagement();
            builder.ConfigureTenantManagement();

            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(TodoAppConsts.DbTablePrefix + "YourEntities", TodoAppConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
        }
    }
}
